package com.example.model;


import com.example.enums.Message;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {
    private Integer status_code;
    private String msg;
    private T data;

    public static Result success(){
        Result result=new Result();
        result.setStatus_code(1);
        return result;
    }

    //返回成功状态码的同时返回对象
    public static <T>Result success(T data){
        Result<T> result=new Result<>();
        result.setStatus_code(1);
        result.setData(data);
        return result;
    }

    public static <T>Result success(T data,Message message){
        Result<T> result=new Result<>();
        result.setStatus_code(1);
        result.setData(data);
        result.setMsg(message.getMsg());
        return result;
    }

    //直接返回错误状态码和错误信息
    public static Result fail(Message errorMsg){
        Result result=new Result();
        result.setStatus_code(0);
        result.setMsg(errorMsg.getMsg());
        return result;
    }

    public static <T>Result fail(T data){
        Result result=new Result();
        result.setStatus_code(0);
        result.setData(data);
        return result;
    }

    //返回错误状态码和错误信息的同时返回错误对象
    public static <T>Result fail(T data,Message errorMsg){
        Result<T> result=new Result<>();
        result.setStatus_code(0);
        result.setMsg(errorMsg.getMsg());
        result.setData(data);
        return result;
    }

}
